package com.chenglai.goods.service;

import com.chenglai.goods.dao.GoodsSpecMapper;
import com.chenglai.goods.pojo.GoodsParam;
import com.chenglai.goods.pojo.GoodsSpec;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;

/**
 * 类描述：
 *
 * @Author rxh
 * @Date 2023/11/17 9:32
 */
@Service
public class GoodsSpecServiceImpl implements GoodsSpecService {

    @Resource
    private GoodsSpecMapper goodsSpecMapper;

    @Override
    public PageInfo getGoodsSpecList(Integer page, Integer size, Integer shopId) {
        PageHelper.startPage(page, size);
        Example example = new Example(GoodsSpec.class);
        Example.Criteria criteria = example.createCriteria();
        criteria.andEqualTo("shopId", shopId);
        example.orderBy("specId").desc();
        return new PageInfo(goodsSpecMapper.selectByExample(example));
    }

    @Override
    public void editGoodsSpec(GoodsSpec goodsSpec) {
        if (goodsSpec.getSpecId() == null) {
            //添加
            goodsSpecMapper.insertSelective(goodsSpec);
        } else {
            //修改
            goodsSpecMapper.updateByPrimaryKeySelective(goodsSpec);
        }
    }

    @Override
    public void delGoodsSpec(Integer specId) {
        goodsSpecMapper.deleteByPrimaryKey(specId);
    }

    @Override
    public GoodsSpec detail(Integer specId) {
        return goodsSpecMapper.selectByPrimaryKey(specId);
    }
}
